﻿#region Copyright
// 
// Copyright (C) 2010 VirtualStaticVoid <virtualstaticvoid@gmail.com>
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
#endregion

namespace IoCWrap
{
  using NUnit.Framework;

  [TestFixture]
  public abstract class IoCWrapTestFixture<TProvider>
    where TProvider : IContainerProvider, new()
  {

    public IContainer Container { get; private set; }

    [TestFixtureSetUp]
    public void TestFixtureSetUp()
    {
      var builder = new TProvider().CreateBuilder();
      builder.AddRegistry(new TestRegistry());
      Container = builder.Build();
    }

    [Test]
    public void InstanceService()
    {
      var service = Container.Resolve<IInstance>();
      service.ShouldNotBeNull();
      Container.Resolve<IInstance>().ShouldNotBeTheSameAs(service);
      Container.Resolve<IInstance>().ShouldNotBeTheSameAs(service);
    }

    [Test]
    public void SingleInstanceService()
    {
      var service = Container.Resolve<ISingleInstance>();
      service.ShouldNotBeNull();
      Container.Resolve<ISingleInstance>().ShouldBeTheSameAs(service);
      Container.Resolve<ISingleInstance>().ShouldBeTheSameAs(service);
    }

    [Test]
    public void NamedInstanceService()
    {
      var service = Container.Resolve<INamedInstance>("NamedInstance");
      service.ShouldNotBeNull();
      Container.Resolve<INamedInstance>("NamedInstance").ShouldNotBeTheSameAs(service);
      Container.Resolve<INamedInstance>("NamedInstance").ShouldNotBeTheSameAs(service);
    }

    [Test]
    public void NamedSingleInstanceService()
    {
      var service = Container.Resolve<INamedSingleInstance>("NamedSingleInstance");
      service.ShouldNotBeNull();
      Container.Resolve<INamedSingleInstance>("NamedSingleInstance").ShouldBeTheSameAs(service);
      Container.Resolve<INamedSingleInstance>("NamedSingleInstance").ShouldBeTheSameAs(service);
    }

    [Test]
    public void CustomConstructionService()
    {
      var service = Container.Resolve<ICustomService>();
      service.ShouldNotBeNull();
      Container.Resolve<ICustomService>().ShouldNotBeTheSameAs(service);
      Container.Resolve<ICustomService>().ShouldNotBeTheSameAs(service);
    }

  }
}
